package com.example.mingyue.controller;


import ch.qos.logback.core.util.StringUtil;
import com.example.mingyue.common.Result;
import com.example.mingyue.model.dto.UserDto;
import com.example.mingyue.service.UserService;
import lombok.extern.slf4j.Slf4j;

import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 普通用户
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 新增普通用户
     * @return
     */
    @GetMapping("/insert")
    public Result addUser(@RequestBody UserDto userDto){

        if(userDto == null){
            return Result.error("请输入账号或密码");
        }
        if(StringUtil.isNullOrEmpty(userDto.getPhone()) || StringUtil.isNullOrEmpty(userDto.getUserPassword())){
            return Result.error("账号或秘密为空");
        }

        userService.insertUser(userDto);

        return Result.success();
    }

    /**
     * 删除普通用户
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteUserById(@PathVariable Integer id){
        userService.deleteUserById(id);
        return Result.success();
    }




}
